/*
 * Copyright 2010 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


package core.api.a1;


import core.api.a4.AlphaNodeFieldConstraint;
import core.api.a4.BetaConstraints;
import core.api.a4.DataProvider;
import core.api.a4.Timer;
import core.impl.p1.BuildContext;
import core.impl.p1.Declaration;
import core.impl.p1.EntryPointNode;
import core.impl.p1.ExistsNode;
import core.impl.p1.JoinNode;
import core.impl.p1.LeftTupleSource;
import core.impl.p1.NotNode;
import core.impl.p1.ObjectSource;
import core.impl.p1.QueryElementNode;
import core.impl.p1.ReactiveFromNode;
import core.impl.p1.RuleBasePartitionId;
import core.impl.p1.WindowNode;
import core.impl.p2.EntryPointId;
import core.impl.p2.ObjectTypeNode;
import core.impl.p2.RuleImpl;
import core.impl.p2.TimerNode;
import core.impl.p4.Accumulate;
import core.impl.p4.AccumulateNode;
import core.impl.p4.AlphaNode;
import core.impl.p4.ConditionalBranchEvaluator;
import core.impl.p4.ConditionalBranchNode;
import core.impl.p4.FromNode;
import core.impl.p4.GroupElement;
import core.impl.p4.LeftInputAdapterNode;
import core.impl.p5.EvalCondition;
import core.impl.p5.EvalConditionNode;
import core.impl.p5.From;
import core.impl.p5.QueryElement;
import core.impl.p5.RightInputAdapterNode;

import java.util.List;

public interface NodeFactory {

    EntryPointNode buildEntryPointNode(int id,
                                       ObjectSource objectSource,
                                       BuildContext context);

    EntryPointNode buildEntryPointNode(int id,
                                       RuleBasePartitionId partitionId,
                                       boolean partitionsEnabled,
                                       ObjectSource objectSource,
                                       EntryPointId entryPoint);


    AlphaNode buildAlphaNode(int id,
                             AlphaNodeFieldConstraint constraint,
                             ObjectSource objectSource,
                             BuildContext context);

    TerminalNode buildTerminalNode(int id,
                                   LeftTupleSource source,
                                   RuleImpl rule,
                                   GroupElement subrule,
                                   int subruleIndex,
                                   BuildContext context);

    ObjectTypeNode buildObjectTypeNode(int id,
                                       EntryPointNode objectSource,
                                       ObjectType objectType,
                                       BuildContext context);

    EvalConditionNode buildEvalNode(int id,
                                    LeftTupleSource tupleSource,
                                    EvalCondition eval,
                                    BuildContext context);


    RightInputAdapterNode buildRightInputNode(int id,
                                              LeftTupleSource leftInput,
                                              LeftTupleSource startTupleSource,
                                              BuildContext context);

    JoinNode buildJoinNode(int id,
                           LeftTupleSource leftInput,
                           ObjectSource rightInput,
                           BetaConstraints binder,
                           BuildContext context);

    NotNode buildNotNode(int id,
                         LeftTupleSource leftInput,
                         ObjectSource rightInput,
                         BetaConstraints binder,
                         BuildContext context);

    ExistsNode buildExistsNode(int id,
                               LeftTupleSource leftInput,
                               ObjectSource rightInput,
                               BetaConstraints binder,
                               BuildContext context);

    AccumulateNode buildAccumulateNode(int id,
                                       LeftTupleSource leftInput,
                                       ObjectSource rightInput,
                                       AlphaNodeFieldConstraint[] resultConstraints,
                                       BetaConstraints sourceBinder,
                                       BetaConstraints resultBinder,
                                       Accumulate accumulate,
                                       boolean unwrapRightObject,
                                       BuildContext context);
    LeftInputAdapterNode buildLeftInputAdapterNode(int nextId,
                                                   ObjectSource objectSource,
                                                   BuildContext context);

    TerminalNode buildQueryTerminalNode(int id,
                                        LeftTupleSource source,
                                        RuleImpl rule,
                                        GroupElement subrule,
                                        int subruleIndex,
                                        BuildContext context);

    QueryElementNode buildQueryElementNode(int nextId,
                                           LeftTupleSource tupleSource,
                                           QueryElement qe,
                                           boolean tupleMemoryEnabled,
                                           boolean openQuery,
                                           BuildContext context);

    FromNode buildFromNode(int id,
                           DataProvider dataProvider,
                           LeftTupleSource tupleSource,
                           AlphaNodeFieldConstraint[] alphaNodeFieldConstraints,
                           BetaConstraints betaConstraints,
                           boolean tupleMemoryEnabled,
                           BuildContext context,
                           From from);

    ReactiveFromNode buildReactiveFromNode(int id,
                                           DataProvider dataProvider,
                                           LeftTupleSource tupleSource,
                                           AlphaNodeFieldConstraint[] alphaNodeFieldConstraints,
                                           BetaConstraints betaConstraints,
                                           boolean tupleMemoryEnabled,
                                           BuildContext context,
                                           From from);

    TimerNode buildTimerNode(int id,
                             Timer timer,
                             final String[] calendarNames,
                             final Declaration[][] declarations,
                             LeftTupleSource tupleSource,
                             BuildContext context);

    ConditionalBranchNode buildConditionalBranchNode(int id,
                                                     LeftTupleSource tupleSource,
                                                     ConditionalBranchEvaluator branchEvaluator,
                                                     BuildContext context);

    WindowNode buildWindowNode(int id,
                               List<AlphaNodeFieldConstraint> constraints,
                               List<Behavior> behaviors,
                               ObjectSource objectSource,
                               BuildContext context);
}
